<template>
  <view class="content">
    <!-- 兑换 -->
    <uni-table stripe >
      <uni-tr>
        <uni-th align="center">兑换物品</uni-th>
        <uni-th align="center">使用积分</uni-th>
        <uni-th align="center">兑换日期</uni-th>
        <uni-th align="center">操作</uni-th>
      </uni-tr>
      <uni-tr v-for="(item,index) in list" :key="index">
        <uni-td align="center">{{ item.prize.prizeName }}</uni-td>
        <uni-td align="center">{{ item.prize.needIntegral }}</uni-td>
        <uni-td align="center">{{ item.prize.createTime.substr(0, item.createTime.length - 8) }}</uni-td>
        <uni-td align="center"><u--text type="primary" text="查看" @click="opentankuang(item)"></u--text></uni-td>
        <!-- {{item.awardType == null ? ' 未选择领奖方式' : item.awardType == 1 ? (item.mailAddress==null?'未填写邮寄地址' :item.mailAddress) : '自提'}} -->
      </uni-tr>
    </uni-table>

    <view v-if="showTankuang" class="tankuang">
      <view v-show="commodity.awardType == 0" class="probablyOne">
        <view class="boxheader">线下自提</view>
        <view class="boxtext">{{ ardss }}</view>
        <view class="boxbtn">
          <view class="btn" style="background-color: #02a7f0;" @click="showTankuang = false">确定</view>
          <view class="btn" style="background-color: #6fb83e;" @click="showTankuang = false">取消</view>
        </view>
      </view>
      <view v-show="commodity.awardType == 1 && commodity.mailAddress !== null" class=" probablyOne">
        <view class="boxheader">物流编码</view>
        <view class="boxtext" selectable='true' >{{ commodity.orderNo == null ? '未邮寄' : commodity.orderNo }}</view>
        <view class="boxbtn">
          <view class="btn" style="background-color: #02a7f0;"  @click=" copyText(commodity.orderNo) , showTankuang = false">{{ commodity.orderNo == null ? '确定' : '复制' }}</view>
          <view class="btn" style="background-color: #6fb83e;" @click="showTankuang = false">取消</view>
        </view>
      </view>
    </view>
    
    <u-loadmore  :status="status" :loading-text="loadingText" :loadmore-text="loadmoreText" :nomore-text="nomoreText" />
  </view>
</template>

<script>
export default {
  data() {
    return {
      list: [],
      // 请求对象
      jifenData: {
        openId: uni.getStorageSync('openid'),
        pageIndex: 1,
        pageSize: 20
      },
      showTankuang: false,
      commodity: {},
      ardss: '',
      status: 'loadmore',
      loadingText: '加载中',
      loadmoreText: '上拉加载',
      nomoreText: '暂无更多'
    };
  },
  onLoad() {
    this.getList();
  },
  onShow() {
    this.getList();
    this.getArdss();
  },
 onReachBottom() {
   console.log(123)
   this.jifenData.pageSize = this.jifenData.pageSize + 10
   this.status = 'loading'
   this.getList()
   // this.status = 'nomore'
 
 },
  methods: {
    
   	// 点击复制订单号
               copyText (res) {
                   uni.setClipboardData({
                       data: res,
                       success: () => {
                           uni.showToast({
                               title: '复制成功'
                           })
                       }
                   })
               },
   
    async getList() {
      const { data } = await uni.$http.post('/prize/findExchangeRecordPageByOpenId', this.jifenData);
      console.log(data);
      if (data.statusCode !== 200) {
        return uni.$u.toast('获取失败');
      } else {
        // uni.$u.toast('获取成功')
        this.list = data.data.data;
        if(this.list.length === data.data.total) {
          this.status = 'nomore'
        }
      }
    },
    opentankuang(item) {
      this.showTankuang = true;
      this.commodity = item;
      console.log(this.commodity);
    },
    async getArdss() {
      const res = await uni.$http.get('/parameter/findAwardAddress');
      console.log(res.data.data.address);
      if (res.statusCode !== 200) {
        return;
      } else {
        this.ardss = res.data.data.address;
      }
    },
    // Reselect() {
    //   this.showTankuang = false;
    //   uni.navigateTo({
    //     url: '../reselectPage/reselectPage?item=' + encodeURIComponent(JSON.stringify(this.commodity))
    //   });
    // }
  }
};
</script>

<style lang="scss" scoped>
.content {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: #ffffff;

  /deep/.uni-table-th {
    font-size: 24rpx !important;
    padding: 20rpx 5rpx !important;
  }

  .tankuang {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50rpx;
    overflow: hidden;
    width: 70%;
    height: 400rpx;
    background-color: #ffffff;
    box-shadow: 0 0 5rpx #ccc;

    .probablyOne {
      width: 100%;
      height: 100%;

      .boxheader {
        height: 100rpx;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: #e8e8e8;
      }

      .boxtext {
        height: 200rpx;
        display: flex;
        justify-content: center;
        align-items: center;
      }

      .boxbtn {
        display: flex;
        justify-content: space-around;
        align-items: center;

        .btn {
          width: 150rpx;
          height: 50rpx;
          border-radius: 10rpx;
          display: flex;
          color: #ffffff;
          justify-content: center;
          align-items: center;
        }
      }
    }
  }
}
</style>
